//
//  HMMainViewController.swift
//  TJHWeiBo
//
//  Created by tianjunhui on 16/8/9.
//  Copyright © 2016年 itcast.cn. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //实例化tabbar
        let tabBar = HMTabBar()
        //设置代理
        tabBar.hmDelegate = self
        
         setValue(tabBar, forKey: "tabBar")
        

        //首页
        addChildViewController(HMHomeViewController(), imaName:"tabbar_home", title: "首页")
        //消息
        addChildViewController(HMMessageViewController(), imaName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(HMDiscoverViewController(), imaName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(HMProfileViewController(), imaName: "tabbar_profile", title: "我")

    }
    
//    封装一个方法
    func addChildViewController(vc: UIViewController, imaName: String, title: String){
        
        //设置title
        vc.navigationItem.title = title
        vc.tabBarItem.title = title
        //设置图片
        vc.tabBarItem.image = UIImage (named: imaName)
        vc.tabBarItem.selectedImage = UIImage (named: "\(imaName)_selected")
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }

   }


//撰写按钮响应点击事件
extension HMMainViewController: HMTabBarDelegate{
    func tabBarButtonClick() {
        print("撰写按钮被点击")
    }
}






